<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AuthRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rule = [
            'action_name'=>'required',
            'action_title'=>'required',
            'module_name'=>[
                'required',
                Rule::in(array_keys(config('app.module_type')))
            ],
            'action_type'=>[
                'required',
                Rule::in(array_keys(config('app.auth_type')))
            ],
            'status'=>'required|boolean',
            'sort'=>'nullable|integer',
        ];

        return $rule;
    }

    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'boolean'=>':attribute只能为0或1',
            'integer'=>':attribute只能整数',
            'in'=>':attribute不在允许的值中',
        ];
    }

    public function attributes()
    {
        return [
            'action_name'=>'功能地址',
            'action_title'=>'功能名称',
            'module_name'=>'模块类型',
            'action_type'=>'功能类型',
            'status'=>'功能状态',
            'sort'=>'排序值',
        ];
    }
}
